import java.util.Map;
import java.util.TreeMap;

public class map {
    public static void main(String[] args) {
        Map<String ,Integer>map=new TreeMap<>();
        map.put("认知觉醒",68);
        map.put("西游记",66);
        map.put("骆驼祥子",58);
        System.out.println(map.get("认知觉醒"));
        //找到就返回对应的value没找到就返回所赋的默认值
        System.out.println(map.getOrDefault("红楼梦",0));
        //返回不重复的集合   根据key的大小进行排序
        System.out.println(map.keySet());
        map.put("西游记",44);
        //value可覆盖
        System.out.println(map.values());
        System.out.println(map.containsKey("被讨厌的勇气"));
        System.out.println(map.containsValue(55));
        //返回所key与value对应关系
        Map<String,Integer>map2=new TreeMap<>();
        String[]arr={"a","b","c","d","a","b","c"};
        for (String s:arr){
            if(!map2.containsKey(s)){
                map2.put(s,1);
            }else {
                int temp=map2.get(s);
                map2.put(s,temp+1);
            }
        }
        for (Map.Entry<String, Integer> entry:map2.entrySet()){
            System.out.println("该字母是"+entry.getKey()+"出现了"+entry.getValue()+"次");
        }
    }
}
